
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , settings = require('./settings')
  , MongoStore = require('connect-mongo')(express)
  , path = require('path')
  , partials = require('express-partials')
  , flash = require('connect-flash');

var app = express();

// all environments
app.configure(function(){
    app.set('port', process.env.PORT || 3030);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'ejs');
    app.use(express.favicon());
    app.use(express.logger('dev'));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(partials());
    app.use(flash());
    app.use(express.cookieParser());
    
    app.use(express.session({
        secret: settings.cookieSecret,
        store: new MongoStore(settings.db)
    }));
    app.use(function(req,res,next){
        res.locals.user = req.session ? req.session.user : '';
        res.locals.error = req.session ? req.flash('error'): '';
        res.locals.success = req.session ? req.flash('success') : '';
        res.locals.info = req.sesion ? req.flash('info') : '';
        next();
    });
    app.use(routes(app));
    app.use(express.static(path.join(__dirname, 'public')));
 });
/*
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(partials());
app.use(flash());
app.use(express.cookieParser());


app.use(function(req,res,next){
    res.local.user = res.session ? req.sessioin.user : '';
    res.local.error = res.session ? req.flash('error') : '';
    res.local.success = res.session ? req.flash('success') : '';
    res.local.info = res.session ? req.flash('info') : '';
    next();
});

app.use(routes(app));
    
app.use(express.static(path.join(__dirname, 'public')));

*/
// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}


http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
